import logging

from flask import Flask, request, Response
from loguru import logger

from src.controller.hardware_controller import hardware_bp

_app = Flask('display_web')

@_app.before_request
def log_filter():
    logger.debug(f'请求url:{request.url}')
    logger.debug(f'请求方法:{request.method}')
    logger.debug(f'\n请求头:{request.headers}')
    if request.method == 'POST':
        if request.is_json:
            json_data = request.get_json()
            logger.debug(f'请求体:{json_data}')
        else:
            # 获取原始请求体
            raw_data = request.data
            print(f'请求体:{raw_data}')

@_app.after_request
def log_filter(response :Response):
    response.headers.add('Content-Type', 'application/json')
    return response

class AppWeb:


    def __init__(self):
        _app.register_blueprint(hardware_bp, url_prefix='/hardware')

    @staticmethod
    def run():
        _app.run()
